#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: api05_measurement.py 
@version:
@time: 2022/03/22 
"""
from TapClientCore.T02_tm_api.v2_api.v2_api_base import *


class Api05MeasurementUrl(V2ApiUrlBase):
    url_measurement_query = api_joint(V2ApiUrlBase().server, Measurement, 'query')
    url_measurement_query_v2 = api_joint(url_measurement_query, 'v2')


class Api05Measurement(V2ApiBase):

    def post_measurement_query(self, payload):
        response = self.tapclient(
            self.post,
            Api05MeasurementUrl.url_measurement_query + self.access_token,
            json=payload
        )
        return response

    def post_measurement_query_v2(self, payload):
        response = self.tapclient(
            self.post,
            Api05MeasurementUrl.url_measurement_query_v2 + self.access_token,
            json=payload
        )
        return response


if __name__ == '__main__':
    T = Api05Measurement()
    import time

    # _payload = {"samples": {"barChartData": {"tags": {"type": "task", "taskId": "62f4bcf01c107a11c2b7ced6"},
    #                                          "fields": ["inputInsertTotal", "inputUpdateTotal",
    #                                                     "inputDeleteTotal", "inputDdlTotal",
    #                                                     "inputOthersTotal", "outputInsertTotal",
    #                                                     "outputUpdateTotal", "outputDeleteTotal",
    #                                                     "outputDdlTotal", "outputOthersTotal"],
    #                                          "type": "instant"}},
    #             "startAt": time.time() * 1000, "endAt": time.time() * 1000, }
    # res = T.post_measurement_query_v2(_payload)
    from pprint import pprint
    #
    # pprint(res)

    _payload2 = {"samples": [{"tags": {"taskId": "62f4d3ea1c107a11c2b7d820", "type": "task"}, "guanluary": "minute",
                              "fields": ["inputQPS", "outputQPS"], "start": time.time() * 1000},
                             {"tags": {"taskId": "62f4d3ea1c107a11c2b7d820", "type": "task"}, "guanluary": "minute",
                              "fields": ["inputTotal", "outputTotal", "insertedTotal", "updatedTotal", "deletedTotal"],
                              "type": "headAndTail"}],
                 "statistics": [{"tags": {"taskId": "62f4d3ea1c107a11c2b7d820", "type": "task"}}]}
    res = T.post_measurement_query(_payload2)
    pprint(res)
